package com.example.springbootschedule.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisConfig {

    private static final String LOCAK_VALUE = "locked";

    @Autowired
    private RedisTemplate redisTemplate;

    public boolean getlock(String lockKey, long expireTime) {
        if (redisTemplate.opsForValue().setIfAbsent(lockKey, LOCAK_VALUE, expireTime, TimeUnit.SECONDS)) {
            return true;
        }
        return false;
    }

}
